# 检查日志的实际创建时间
Write-Host "=== 检查日志创建时间 ===" -ForegroundColor Green

# 1. 获取所有日志
Write-Host "`n1. 获取所有日志..." -ForegroundColor Yellow
try {
    $logsResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/log/list?pageSize=100" -Method GET
    Write-Host "✓ 获取到 $($logsResponse.total) 条日志" -ForegroundColor Green
    
    if ($logsResponse.logs.Count -gt 0) {
        Write-Host "`n日志创建时间分析:" -ForegroundColor Cyan
        foreach ($log in $logsResponse.logs) {
            Write-Host "日志ID: $($log.id), 创建时间: $($log.createdAt)" -ForegroundColor White
        }
        
        # 检查最早的日志时间
        $earliestLog = $logsResponse.logs | Sort-Object createdAt | Select-Object -First 1
        Write-Host "`n最早的日志时间: $($earliestLog.createdAt)" -ForegroundColor Yellow
        
        # 检查最晚的日志时间
        $latestLog = $logsResponse.logs | Sort-Object createdAt -Descending | Select-Object -First 1
        Write-Host "最晚的日志时间: $($latestLog.createdAt)" -ForegroundColor Yellow
    }
} catch {
    Write-Host "✗ 获取日志失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 2. 测试不同的清理日期
Write-Host "`n2. 测试不同的清理日期..." -ForegroundColor Yellow

$testDates = @(
    "2025-01-01T00:00:00.000Z",
    "2025-07-01T00:00:00.000Z", 
    "2025-08-01T00:00:00.000Z",
    "2025-08-02T00:00:00.000Z",
    "2025-08-03T00:00:00.000Z"
)

foreach ($testDate in $testDates) {
    Write-Host "`n测试日期: $testDate" -ForegroundColor Cyan
    try {
        $cleanResponse = Invoke-RestMethod -Uri "http://localhost:5252/api/log/clean?beforeDate=$testDate" -Method DELETE
        Write-Host "清理结果: $($cleanResponse.message)" -ForegroundColor Green
    } catch {
        Write-Host "清理失败: $($_.Exception.Message)" -ForegroundColor Red
    }
}

Write-Host "`n=== 检查完成 ===" -ForegroundColor Green 